package com.api.shopapi.mapper;

import com.api.shopapi.entity.NursingLevel;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface NursingLevelMapper {

    @Select("select  * from nursing_level where institutionCode =#{institutionCode} and Status=0 order by sort desc")
    List<NursingLevel> getList(String institutionCode);

    @Insert("insert into nursing_level " +
            "(NursingLevelCode,Name,Sort,Status,StaffCode,InstitutionCode,Price,PriceMonth) " +
            "values (#{nursingLevel.nursingLevelCode} ,#{nursingLevel.name} ,#{nursingLevel.sort} ,#{nursingLevel.status} ,#{nursingLevel.staffCode} ,#{nursingLevel.institutionCode},#{nursingLevel.Price},#{nursingLevel.PriceMonth} )")
    int insert(@Param("nursingLevel") NursingLevel nursingLevel);

    @Update("update nursing_level set  Name=#{nursingLevel.name} ,Sort=#{nursingLevel.sort} ,Status=#{nursingLevel.status} ," +
            "StaffCode=#{nursingLevel.staffCode} ,InstitutionCode=#{nursingLevel.institutionCode},Price=#{nursingLevel.Price},PriceMonth=#{nursingLevel.PriceMonth} " +
            "where NursingLevelCode=#{nursingLevel.nursingLevelCode}  ")
    int update(@Param("nursingLevel") NursingLevel nursingLevel);

    @Delete("delete from nursing_level where nursingLevelCode=#{nursingLevelCode} ")
    int delete(@Param("nursingLevelCode") String nursingLevelCode);

    @Select("select  * from nursing_level where name =#{name} and institutionCode=#{institutionCode} limit 1")
    NursingLevel getByNameAndInstitutionCode(@Param("name") String name, @Param("institutionCode") String institutionCode);

    @Select("select * from nursing_level where nursingLevelCode=#{nursingLevelCode} limit 1")
    NursingLevel getByNursingLevelCode(@Param("nursingLevelCode") String nursingLevelCode);

    @Select("<script>" +
            "select  * from nursing_level " +
            "where institutionCode =#{institutionCode} " +
            "<if test ='name !=null and name!=\"\" '>" +
            "and Name like concat('%',#{name},'%') " +
            "</if>" +
            "<if test ='status !=-1 '>" +
            "and Status =#{status} " +
            "</if>" +
            "order by sort desc" +
            "</script>")
    List<NursingLevel> getPageInfo(@Param("institutionCode") String institutionCode,@Param("name") String name,@Param("status") int status);


    @Select("<script>" +
            "select  * from nursing_level " +
            " where institutionCode in (select institutionCode from institution where governmentCode=#{governmentCode} ) " +
            " order by sort desc" +
            "</script>")
    List<NursingLevel> listByGovCode(@Param("governmentCode") String governmentCode);


}
